<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<head>
<%@include file="/WEB-INF/jsp/qsws/commons/head.jsp"%>
<link rel="stylesheet" type="text/css" href="resources/qsws/css/zixunL.css">
<script src="resources/qsws/js/index.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function() {
		/* var infoListUrl = "api/aticle/articleList";
		var sendData = {"pageNumber":1,"pageSize":6};
		var hasData = true;
		query(infoListUrl,sendData);
		 $('.content').dropload({
							scrollArea : window,
							domUp : {
								domClass : 'dropload-up',
								domRefresh : '<div class="dropload-refresh">↓下拉刷新</div>',
								domUpdate : '<div class="dropload-update">↑释放更新</div>',
								domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'
							},
							domDown : {
								domClass : 'dropload-down',
								domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
								domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
								domNoData : '<div class="dropload-noData">暂无数据</div>'
							},
							loadUpFn : function(me) {
								$('section ul li:not(.content ul li:first)').remove();
								//sendData.pageNumber = 1;
								query(infoListUrl,sendData);
								me.resetload();
								me.noData(true);
							},
							loadDownFn : function(me) {
								console.log(sendData.pageNumber);
								sendData.pageNumber = sendData.pageNumber + 1;
								//query(infoListUrl,sendData);
								if(!query(infoListUrl,sendData)){
									me.noData(true); 
								}else{
									me.noData(false);
								}
								me.resetload();
							},
							threshold : -10,
							//distance:2
						}); 
						
		function query(url,sendData) {
			$.getJSON(url, sendData,function(data) {
				if (data == null) {
					alert('无任何数据，请检查接口是否正确')
					hasData = false;  
				}
				var list = data.articleList;
				if(list != null){
					if(list.length == 0){
						hasData = false;  
					}
					for (var i in list) {
						var information = list[i];
						var $a = $('.content ul a:first').clone();
						$a.attr('href','qsws/toArticleDetailPage?articleId=' + information.id);
						$a.find('.img').children('img').attr('src',information.img);
						$a.find('.title').text(information.title);
						$a.find('.source').text(information.source?information.source:'暂无');
						$a.find('.browse_count').text(information.browse?information.browse:0);
						$a.find('.date').text(<fmt:formatDate value="${information.create_time }" pattern="yyyy-MM-dd"/>);
						$a.show();
						$('.content ul').append($a); 
					}
				}
			})
			return hasData;
		}  */
		var infoListUrl = "api/aticle/articleList";
		var sendedData = {"pageNumber":1,"pageSize":6};
		var loading = false;
		query(infoListUrl,sendedData);
		$(window).scroll(function(){
			if (($(window).scrollTop() + $(window).height() > $(document).height() - 10) && !loading) {
				loading = true;
				sendedData.pageNumber = sendedData.pageNumber + 1;
				query(infoListUrl,sendedData);
				console.log(sendedData.pageNumber);
			}
		})
		
		function query(url,sendedData) {
			$.getJSON(url, sendedData,function(data) {
				loading = false;
				if (data == null) {
					alert('无任何数据，请检查接口是否正确');
					return;  
				}
				var list = data.articleList;
				if(list != null){
					if(list.length == 0){
						return;  
					}
					for (var i in list) {
						var information = list[i];
						var $a = $('.content ul a:first').clone();
						$a.attr('href','qsws/toArticleDetailPage?articleId=' + information.id);
						$a.find('.img').children('img').attr('src',information.img);
						$a.find('.title').text(information.title);
						$a.find('.source').text(information.source?information.source:'暂无');
						$a.find('.browse_count').text(information.browse?information.browse:0);
						$a.find('.date').text(<fmt:formatDate value="${information.create_time }" pattern="yyyy-MM-dd"/>);
						$a.show();
						$('.content ul').append($a); 
					}
				}
			})
		}
		
	}) 
</script>
</head>
<body>
	<!-- 头部 -->
	<header>
		<h1>资讯列表</h1>
	</header>
	<!-- 内容 -->
	<section>
		<div class="swiper1 swiper-container">
			<div class="swiper-wrapper">
				<div class="swiper-slide">
					<img src="resources/qsws/img/img1.jpg" alt="">
				</div>
				<div class="swiper-slide">
					<img src="resources/qsws/img/img2.jpg" alt="">
				</div>
				<div class="swiper-slide">
					<img src="resources/qsws/img/img3.jpg" alt="">
				</div>
				<div class="swiper-slide">
					<img src="resources/qsws/img/img2.jpg" alt="">
				</div>
			</div>
			<div class="swiper-pagination"></div>
		</div>
		<div class="content">
			<ul>
				<a href="" style="display:none;"><li>
						<div class="img l">
							<img src="resources/qsws/img/kecheng.jpg"
								onerror="this.src='resources/qsws/img/kecheng.jpg'" alt="">
						</div>
						<div class="words r">
							<p class="title">独立自主的法治道路独立自主的法治道路</p>
							<p class="xueshi clearfix">
								<span class="source l">学习时报</span><span class="browse_count r">34</span><span
									class="date r">2016-05-02</span>
							</p>
						</div> <img src="resources/qsws/img/li_bak1.png" alt="" class="sanj">
				</li>
				</a>
			</ul>
		</div>
	</section>
</body>
</html>